import os
import configparser

from src.settings import BASE_DIR


class ConfigParser():
    def __init__(self):
        self.config_path = os.path.join(BASE_DIR, "yunding.ini")
        self.conf = configparser.ConfigParser()
        self.conf.read(self.config_path, encoding="utf-8")

    def get(self):
        token = self.conf.get("token", "access_token")
        return token

    def set(self, token):
        self.conf.set("token", "access_token", token)
        self.conf.write(open(self.config_path, "w+", encoding="utf-8"))

    def get_appid(self):
        return self.conf.get("wxmini", "appid")

    def get_appsecret(self):
        return self.conf.get("wxmini", "secret")

    def get_mch_id(self):
        return self.conf.get("wxmini", "mchid")
